<?php include_once('includes/header.php');?>
<?php include_once(inc('repository.php'));?>
<?php
	parameters_check($_REQUEST['word']);
	$sql='SELECT w.id,word,definition,familiarity,created_at FROM `voca_words` AS w'.
		' LEFT JOIN `voca_definitions` AS def ON def.word_id = w.id and ( def.user_id=? or def.is_standard=1)'.
		' LEFT JOIN `voca_user_words` AS uw ON uw.word_id = w.id AND uw.user_id = ? '.
		' WHERE word = ?';
	$stmt = Repository::prepare($sql);
	$word_str=urldecode($_REQUEST['word']);
	$user_id=user_val('id');
	$stmt -> bind_param('iis',$user_id,$user_id,$word_str);
	$stmt -> execute();
	$word = Repository::get_result($stmt)[0];
?>
<div id="main" class="word">
	<?php if($word==NULL):?>
		<span class="panel_title">
			<span class="word"><?php e(strip_tags(strip_quotes($_REQUEST['word'])))?></span>
		</span>
		<div id="word_list" class="content">
			非常抱歉，从我们的词库中无法找到单词<?php e(strip_quotes(strip_tags($_REQUEST['word'])))?>的定义。
			<a href="javascript:void(0);" id="to_add_words">添加单词定义</a>
			<form id="redirect_to_add_words" action="add_words.php" method="POST">
				<input type="hidden" value='["<?php e(strip_quotes(strip_tags($_REQUEST['word'])))?>"]' name="words" />
			</form>
		</div>
	<?php else: ?>
	<span class="panel_title">
		<?php e(word_stylish($word['word'],$word['familiarity'])); ?>
		<?php if($word['created_at']): ?>
			<span class="collected_at panel_bar">
				已在个人词库中，收藏于<?php e(time_ago(strtotime($word['created_at'])))?>
			</span>
		<?php else:?>
			<div class="panel_bar">
			<a href="javascript:void(0)" data="<?php e($word['id']);?>" class="collect_word">收藏</a>
			</div>
		<?php endif ?>
	</span>
	<?php progress_bar(20*$word['familiarity'])?>
	<div id="word_list" class="content">
		<div class="definition corner">
			<div><?php e($word['definition'])?></div>
			<a href="#" class="btn_edit_definition">修改定义</a>
		</div>
		<div class='tabs sentences'>
			<ul class='etabs'>
				<li class='tab'>
					<a href="/snippets/sentences.php?type=all&word_id=<?php e($word['id']) ?>" data-target="#tabs_sentences">所有例句</a>
				</li>
				<li class='tab'>
					<a href="/snippets/sentences.php?type=ilike&word_id=<?php e($word['id']) ?>" data-target="#tabs_collected_sentences">我的收藏</a>
				</li>
				<li class='tab'>
					<a href="/snippets/sentences.php?type=mime&word_id=<?php e($word['id']) ?>" data-target="#tabs_my_sentences">我创建的</a>
				</li>
				<a href="#" class="btn_open_sentence_dialog">添加例句</a>
			</ul>
			<div class="panel_container">
				<div id="tabs_sentences">
					<img src="/assets/images/ajax-loader.gif" width="31" height="31" align="absmiddle"/>&nbsp;例句加载中...
				</div>
				<div id="tabs_collected_sentences">
					<img src="/assets/images/ajax-loader.gif" width="31" height="31" align="absmiddle"/>&nbsp;例句加载中...
				</div>
				<div id="tabs_my_sentences">
					<img src="/assets/images/ajax-loader.gif" width="31" height="31" align="absmiddle"/>&nbsp;例句加载中...
				</div>
			</div>
		</div>
		<div class='tabs notes'>
			<ul class='etabs'>
				<li class='tab'><a href="/snippets/notes.php?type=all&word_id=<?php e($word['id']) ?>" data-target="#tabs_notes">所有笔记</a></li>
				<li class='tab'><a href="/snippets/notes.php?type=ilike&word_id=<?php e($word['id']) ?>" data-target="#tabs_collected_notes">我的收藏</a></li>
				<li class='tab'><a href="/snippets/notes.php?type=mime&word_id=<?php e($word['id']) ?>" data-target="#tabs_my_notes">我创建的</a></li>
				<a href="#" class="btn_open_note_dialog">添加笔记</a>
			</ul>
			<div class='panel_container'>
				<div id="tabs_notes">
					<img src="/assets/images/ajax-loader.gif" width="31" height="31" align="absmiddle"/>&nbsp;笔记加载中...
				</div>
				<div id="tabs_collected_notes">
					<img src="/assets/images/ajax-loader.gif" width="31" height="31" align="absmiddle"/>&nbsp;笔记加载中...
				</div>
				<div id="tabs_my_notes"><img src="/assets/images/ajax-loader.gif" width="31" height="31" align="absmiddle"/>&nbsp;笔记加载中...
				</div>
			</div>
		</div>
	</div>
	<!--dialogs-->
	<div class="dialog corner hidden" id="edit_definition_dialog">
		<div class="dialog_header">修改单词定义</div>
		<div class="dialog_content">
			<div>
				<label for="definition_input"><?php e($word['word']); ?></label>
				<input type="text" class="text_input_simple" id="definition_input" value="<?php e($word['definition'])?>"/>
				<input type="hidden" id="old_definition" value="<?php e($word['definition'])?>"/>
			</div>
			<div class="response"></div>
		</div>
		<div class="dialog_footer">
			<input type="button" class="btn" value="保存定义" id="btn_edit_definition" />&nbsp;&nbsp;
			<a href="javascript:void(0)" class="btn_close_dialog">取消</a>
		</div>
	</div>
	<div class="dialog corner hidden" id="sentence_dialog">
		<div class="dialog_header">添加例句</div>
		<div class="dialog_content">
			<input type="hidden" id="sentence_id"/>
			<div>
			<label for="sentence_input">例句</label>
			<input type="text" class="text_input_simple" id="sentence_input"/>
			</div>
			<div>
			<label for="translation_input">翻译</label>
			<input type="text" class="text_input_simple" id="translation_input"/>
			</div>
			<div class="response"></div>
		</div>
		<div class="dialog_footer">
			<input type="button" class="btn" value="保存例句" id="btn_save_sentence" />&nbsp;&nbsp;
			<a href="javascript:void(0)" class="btn_close_dialog">取消</a>
		</div>
	</div>
	<div class="dialog corner hidden" id="note_dialog">
		<div class="dialog_header">添加笔记</div>
		<div class="dialog_content">
			<input type="hidden" id="note_id"/>
			<textarea id="note_input" class="corner"></textarea>
			<div class="response"></div>
		</div>
		<div class="dialog_footer">
			<input type="button" class="btn" value="保存笔记" id="btn_save_note" />&nbsp;&nbsp;
			<a href="javascript:void(0)" class="btn_close_dialog">取消</a>
		</div>
	</div>
	<?php endif?>
	<input type="hidden" id="data_word_id" value="<?php e($word['id']) ?>"/>
</div>
<script type="text/javascript" src="/assets/javascripts/jquery.easytabs.min.js"></script>
<?php get_footer();?>